import Mock from "mockjs";
//处理路径传参
import { parameteUrl } from "@/utils/query-param"

function ArrSet(Arr: any[], id: string): any[] {
    let obj: any = {}
    const arrays = Arr.reduce((setArr, item) => {
        obj[item[id]] ? '' : (obj[item[id]] = true && setArr.push(item))
        return setArr
    }, [])
    return arrays
}
/**
* @description: min ≤ r ≤ max  随机数
* @param {*} Min
* @param {*} Max
* @return {*}
*/
function RandomNumBoth(Min: any, Max: any) {
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}
//左中
export default [
    {
        url: "/bigscreen/countUserNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    offlineNum: '@integer(50, 100)',
                    alarmNum: '@integer(20, 100)',
                    lockNum: '@integer(10, 50)',
                    totalNum: 368
                }
            })
            a.data.onlineNum = a.data.totalNum - a.data.offlineNum - a.data.lockNum - a.data.alarmNum
            return a
        },
    },
    {
        url: "/bigscreen/countDeviceNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    alarmNum: '@integer(100, 1000)',
                    offlineNum: '@integer(0, 50)',
                    totalNum: 698
                }
            })
            a.data.onlineNum = a.data.totalNum - a.data.offlineNum
            return a
        }
    },
    //左下
    {
        url: "/bigscreen/leftBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list|20": [
                        {
                            provinceName: "@province()",
                            cityName: '@city()',
                            countyName: "@county()",
                            createTime: "@datetime('yyyy-MM-dd HH:mm:ss')",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno|+1": 10000,
                            "onlineState|1": [0, 1],

                        }
                    ]
                }
            })
            return a
        }
    },
    //右上
    {
        url: "/bigscreen/alarmNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    dateList: ['2021-11', '2021-12', '2022-01', '2022-02', '2022-03', "2022-04"],
                    "numList|6": [
                        '@integer(0, 1000)'
                    ],
                    "numList2|6": [
                        '@integer(0, 1000)'
                    ]
                }
            })
            return a
        }
    },
    //右中
    {
        url: "/bigscreen/ranking",
        type: "get",
        response: () => {
            let num = Mock.mock({ "list|80": [{ value: "@integer(50,1000)", name: "@city()" }] }).list
            //   console.log("ranking",num);
            let newNum: any = [], numObj: any = {}
            num.map((item: any) => {
                if (!numObj[item.name] && newNum.length < 8) {
                    numObj[item.name] = true
                    newNum.push(item)
                }
            })
            let arr = newNum.sort((a: any, b: any) => {
                return b.value - a.value
            })
            let a = {
                success: true,
                data: arr
            }
            return a
        }
    },
    //右下
    {
        url: "/bigscreen/rightBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list|40": [{
                        alertdetail: "@csentence(5,10)",
                        "alertname|1": ["水浸告警", "各种报警"],
                        alertvalue: "@float(60, 200)",
                        createtime: "2022-04-19 08:38:33",
                        deviceid: null,
                        "gatewayno|+1": 10000,
                        phase: "A1",
                        sbInfo: "@csentence(10,18)",
                        "terminalno|+1": 100,
                        provinceName: "@province()",
                        cityName: '@city()',
                        countyName: "@county()",
                    }],

                }
            })
            return a
        }
    },
    //安装计划
    {
        url: "/bigscreen/installationPlan",
        type: "get",
        response: () => {

            let num = RandomNumBoth(26, 32);
            const a = Mock.mock({
                ["category|" + num]: ["@city()"],
                ["barData|" + num]: ["@integer(10, 100)"],
            })
            let lineData = [], rateData = [];
            for (let index = 0; index < num; index++) {
                let lineNum = Mock.mock('@integer(0, 100)') + a.barData[index]
                lineData.push(lineNum)
                let rate = a.barData[index] / lineNum;
                rateData.push((rate * 100).toFixed(0))
            }
            a.lineData = lineData
            a.rateData = rateData
            return {
                success: true,
                data: a
            }
        }
    },
    {
        url: "/bigscreen/centerMap",
        type: "get",
        response: (options: any) => {
            let params = parameteUrl(options.url)
            //不是中国的时候
            if (params.regionCode && !["china"].includes(params.regionCode)) {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|100": [
                            {
                                name: "@city()",
                                value: '@integer(1, 1000)'
                            }
                        ],
                        regionCode: params.regionCode,//-代表中国
                    }
                })
                return a
            } else {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|12": [
                            {
                                name: "@province()",
                                value: '@integer(1, 1100)'
                            }
                        ],
                        regionCode: 'china',
                    }
                })
                // 去重
                a.data.dataList = ArrSet(a.data.dataList, "name")
                return a
            }
        }
    },
    
    // 绿电页面模拟接口
    {
        url: "/green-power/power-curve",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    'list|24': [{
                        time: '@datetime("HH:mm")',
                        power: '@integer(800, 1200)',
                        efficiency: '@integer(85, 98)'
                    }],
                    totalPower: '@integer(20000, 30000)',
                    avgEfficiency: '@integer(90, 95)'
                }
            })
        }
    },
    {
        url: "/green-power/generation-chart",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    'regions|6': [{
                        name: '@city',
                        'data|12': ['@integer(100, 500)'],
                        color: '@color'
                    }],
                    months: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                }
            })
        }
    },
    {
        url: "/green-power/distribution-map",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    'facilities|20': [{
                        id: '@id',
                        name: '@ctitle(4, 8)',
                        type: '@pick(["风电", "光伏", "水电", "生物质"])',
                        lat: '@float(30, 40, 2, 6)',
                        lng: '@float(110, 120, 2, 6)',
                        capacity: '@integer(50, 500)',
                        status: '@pick(["运行", "维护", "停机"])',
                        output: '@integer(80, 450)'
                    }],
                    'regions|8': [{
                        name: '@province',
                        totalCapacity: '@integer(1000, 5000)',
                        currentOutput: '@integer(800, 4000)',
                        efficiency: '@integer(85, 98)'
                    }]
                }
            })
        }
    },
    {
        url: "/green-power/supply-data",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    'list|15': [{
                        deviceName: '@ctitle(6, 12)',
                        region: '@city',
                        capacity: '@integer(50, 300)',
                        dailyOutput: '@integer(10000, 80000)',
                        efficiency: '@integer(80, 98)',
                        status: '@pick(["normal", "warning", "error"])',
                        lastUpdate: '@datetime("yyyy-MM-dd HH:mm:ss")'
                    }],
                    total: '@integer(100, 200)',
                    totalCapacity: '@integer(5000, 10000)',
                    totalOutput: '@integer(800000, 1500000)'
                }
            })
        }
    },
    {
        url: "/green-power/waste-utilization",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    'daily|7': [{
                        date: '@date("MM-dd")',
                        utilization: '@integer(60, 95)',
                        waste: '@integer(100, 500)'
                    }],
                    'monthly|12': [{
                        month: '@integer(1, 12)',
                        utilization: '@integer(70, 90)',
                        total: '@integer(5000, 15000)'
                    }],
                    currentUtilization: '@integer(80, 95)',
                    totalWaste: '@integer(50000, 100000)'
                }
            })
        }
    },
    {
        url: "/green-power/waste-reception",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    'sources|5': [{
                        name: '@ctitle(4, 8)',
                        reception: '@integer(1000, 8000)',
                        percentage: '@integer(10, 30)',
                        trend: '@pick(["up", "down", "stable"])'
                    }],
                    totalReception: '@integer(30000, 60000)',
                    'hourlyData|24': [{
                        hour: '@integer(0, 23)',
                        reception: '@integer(800, 2500)'
                    }]
                }
            })
        }
    },
    {
        url: "/green-power/nav-statistics",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    totalCapacity: '@integer(8000, 12000)',
                    currentOutput: '@integer(6000, 9000)',
                    efficiency: '@integer(85, 95)',
                    onlineDevices: '@integer(180, 220)',
                    totalDevices: '@integer(200, 250)',
                    carbonReduction: '@integer(15000, 25000)',
                    'trends|7': [{
                        date: '@date("MM-dd")',
                        output: '@integer(5000, 8000)',
                        efficiency: '@integer(80, 95)'
                    }]
                }
            })
        }
    }
];

